package com.example.blew.demo;

import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.Digester;
import cn.hutool.crypto.digest.HMac;
import com.alibaba.excel.EasyExcel;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.example.blew.demo.model.DemoData;
import com.example.blew.demo.uitl.*;
import lombok.Data;
import org.junit.jupiter.api.Test;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;

import static cn.hutool.crypto.digest.HmacAlgorithm.HmacMD5;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author chaodong.zeng@pcitc.com
 * @since 2022/8/16
 */
public class JunitTest {

    @Resource
    DataAddFactory dataAddFactory;

    @Test
    public void test() {
        String name = "Lihao";
        fun(name);
        System.out.println(name);

    }

    private void fun(String name) {
        String nam = new String("hello");
        name = nam;

    }


    @Test
    public void UUID() {
//        UUID uuid4 = UUID.randomUUID();
//        int version4 = uuid4.version();
//        System.out.println("UUID:"+ uuid4+" 版本 " + version4);

        String str = StrUtil.uuid().replaceAll("-", "");
        System.out.println("UUID:" + str);

    }

    @Test
    void contextLoads() {

        HashMap<String, Object> map = new HashMap<>();

        //获取日历对象
        Calendar instance = Calendar.getInstance();
        //默认30S过期
        instance.add(Calendar.SECOND, 30);

        String token = JWT.create()
                .withHeader(map)     //header,可以不写
                .withClaim("userId", 21)    //payload
                .withClaim("username", "Garry")   //payload
                .withExpiresAt(instance.getTime())    //设置过期时间
                .sign(Algorithm.HMAC256("!ISN!@#￥%"));   //签名

        System.out.println(token);
    }


    @Test
    public void tetsexcel() {
        // 写法1：JDK8+ ,不用额外写一个DemoDataListener
        // since: 3.0.0-beta1
        String fileName = "D:\\整理文档\\20220920\\测试文件夹\\工作簿2.xls";
        File file = new File(fileName);
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        // 这里每次会读取3000条数据 然后返回过来 直接调用使用数据就行
        EasyExcel.read(file, DemoData.class, new DemoDataListener()).sheet().doRead();

    }

    @Test
    public void getP() {
        for (int jj = 0; jj < 10; jj++) {
            int tmp = (int) (Math.random() * 100) % 2 + 2;
            System.out.println(tmp);
        }

        String ID_18 = "321083197812162119";
        IdcardUtil.Idcard idcardInfo = IdcardUtil.getIdcardInfo(ID_18);
        String ip = "82.157.250.161";
        System.out.println(idcardInfo);
        InetAddress inetAddress = null;
        try {
            inetAddress = InetAddress.getByName("127.0.0.1");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        byte[] localHardwareAddress = NetUtil.getHardwareAddress(inetAddress);
        byte[] localHardwareAddress1 = NetUtil.getLocalHardwareAddress();
        String macAddress = NetUtil.getMacAddress(inetAddress);

    }

    @Data
    class User {
        private String name;
        private int age;

        public User(String name, int age) {
            this.name = name;
            this.age = age;
        }


    }

    @Test
    public void readPic() {
        System.out.println("开始读取图片信息...");
        File jpegFile = new File("D:\\app\\img\\123ed.jpg");
        Metadata metadata;
        try {
            metadata = JpegMetadataReader.readMetadata(jpegFile);
            Iterator<Directory> it = metadata.getDirectories().iterator();
            while (it.hasNext()) {
                Directory exif = it.next();
                Iterator<Tag> tags = exif.getTags().iterator();

                while (tags.hasNext()) {
                    Tag tag = (Tag) tags.next();
                    String tagName = tag.getTagName();  //标签名
                    String desc = tag.getDescription(); //标签信息
                    System.out.println(tag);
                    if (tagName.equals("GPS Longitude")) {
                        System.err.println("经度: " + desc);
                        System.err.println("经度(度分秒格式): " + desc.toString());
                    }
                }
            }
            System.out.println("图片信息读取完成！");
        } catch (JpegProcessingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void getFun() {
        User user1 = new User("张三1", 18);
        User user2 = new User("张三2", 18);
        User user3 = new User("张三3", 18);
        User user4 = new User("张三4", 18);
        User user5 = new User("张三5", 18);

        Field[] fields = ReflectUtil.getFields(User.class);
        Object[] Object = ReflectUtil.getFieldsValue(user1);

        for (Object t : Object) {
            String s = t.toString();

        }


    }

    @Test
    public void fun() {
        String s = "MCMXCIV";
        Map<String, Integer> map = new HashMap<>();
        map.put("I", 1);
        map.put("V", 5);
        map.put("X", 10);
        map.put("L", 50);
        map.put("C", 100);
        map.put("D", 500);
        map.put("M", 1000);
        int tmp = -1;
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            tmp = i > 0 ? map.get("" + s.charAt(i - 1)) : map.get("" + s.charAt(0));
            if (map.get("" + s.charAt(i)) > tmp) {
                // 遇到比自己大的数回退，回退到跟自己一样大
                bre:
                for (int j = i - 1; j >= 0; j--) {
                    if (map.get("" + s.charAt(j)) < map.get("" + s.charAt(i))) {
                        sum = sum - (2 * map.get("" + s.charAt(j)));
                    } else {
                        break bre;
                    }
                }
            }
            sum += map.get("" + s.charAt(i));
        }
        String s1 = fun2("cir", "car");

    }

    public String fun2(String st1, String str2) {
        String s = "";
        for (int i = 0; i < st1.length() && i < str2.length(); i++) {
            if (st1.charAt(i) == str2.charAt(i)) {
                s += st1.charAt(i);
            }
        }
        return s;
    }

    public Boolean fun2(String s) {
        int length = s.length() / 2;


        return true;
    }

    @Test
    public void removeDuplicates() {
        int[] nums = {-3, -1, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        Set<Integer> set = new TreeSet<>();
        for (int num : nums) {
            set.add(num);
        }
        Integer[] integers = set.toArray(new Integer[set.size()]);
        int[] arr = new int[integers.length];
        for (int i = 0; i < integers.length; i++) {
            arr[i] = integers[i];
//            "".equals()
        }
    }

    public int[] fun(int[] nums, int i) {
        for (; i < nums.length; i++) {
            nums[i - 1] = nums[i];
        }
        return nums;
    }


    @Test
    public void fun22(){
        int t=1<<3;
        String a="1001";
        String b="0010";
        Boolean flag=true;
        for(int i=a.length(),j=b.length();i>=0 && j>=0;i--,j--){
        }
    }


    @Test
    public void lengthOfLastWord() {
        HMac hmac = SecureUtil.hmac(HmacMD5, "12112");
        Digester digester = DigestUtil.digester("sm212213");

//136ce3c86e4ed909b76082055a61586af20b4dab674732ebd4b599eef080c9be
        String digestHex = digester.digestHex("aaaaa");
    }
    @Test
    public void funff(){
         int i='1';
         StringBuilder stringBuilder=new StringBuilder();
         stringBuilder.append(1212);
         String str=new String(stringBuilder);
         int tm=1%2;
         int ss=2%2;
    }

    @Test
    public void  addBinary() {
        int i=2147483647;
        int j=46340*46340;


    }

    @Test
    public void climbStairs() {
         int n=3;
        if(n<=2){
            return;
        }
        int dp[]=new int[n+1];
        dp[1]=1;
        dp[2]=2;
        for(int i=3;i<=n;i++){
            dp[i]=dp[i-1]+dp[i-2];
        }
        return;
    }




}